﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XCommunity.Forums.Views;
using XCommunity.Web;
using XCommunity.Forums;
using XCommunity.Views;
using XCommunity.Web.UI;

public partial class Forums_FrameView : System.Web.UI.Page
{

  protected ForumsSystem Forums
  {
    get { return WebCommunityContext.Current.ForumsSystem; }
  }

  public string Route
  {
    get;
    private set;
  }

  protected ViewObject View
  {
    get;
    private set;
  }


  protected void Page_Init( object sender, EventArgs e )
  {
    Route = Request.QueryString["route"];
    Items["Route"] = Route;

    View = Forums.ViewService.GetView( Route );

    PresenterContainer.View = View;
    PresenterContainer.Controls.Add( GetPresenter( View ) );


    var navigator = Forums.ViewService.GetNavigatorView( Route );

    RoutePresenter.DataSource = navigator.GetRouteItems();

    Title = string.Format( "XCommunity - {0}", navigator.Title );
  }


  protected void Page_Load( object sender, EventArgs e )
  {
    Response.Cache.SetCacheability( HttpCacheability.NoCache );

    DataBind();
  }


  protected Control GetPresenter( ViewObject view )
  {

    if ( view is ForumsView )
      return LoadControl( "Presenters/ForumsFramePresenter.ascx" );

    else if ( view is PanelFrameView )
      return LoadControl( "Presenters/PanelFramePresenter.ascx" );

    else if ( view is TopicFrameView )
      return LoadControl( "Presenters/TopicFramePresenter.ascx" );

    else
      throw new NotSupportedException();
  }

}
